package com.atguigu.yygh.Controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.service.HospitalService;
import com.atguigu.yygh.service.HospitalSetService;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @description: TODO
 * @author: 化一帆
 * @date: 2022/11/29 13:58
 * @version: v1.0
 */
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
//@CrossOrigin
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    /**
     * @description: 医院列表的分页查询[条件分页查询]
     * 通过Service_hosp去调用Service_cmn得到医院等级的名称，最终在页面中做一个显示
     * @author 化一帆
     * @date 2022/11/29 14:01
     */

    @GetMapping("list/{page}/{limit}")
    public R listHosp(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo) {
        //TODO 需要查询的数据存储在Mongodb中，所以返回的page对象的domain包下的
        Page<Hospital> pageModel = hospitalService.selectHospitalPage(page, limit, hospitalQueryVo);
        List<Hospital> content = pageModel.getContent();
        long totalElements = pageModel.getTotalElements();
        return R.ok().data("pages", pageModel);//给前端你的response中返回数据，方便从中拿到后端的传递的数据，以便在页面显示
    }

    /**
     * @description: 更新医院的上线状态
     * @author 化一帆
     * @date 2022/11/29 21:38
     */
    @ApiOperation("更新医院的上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public R updateHospStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
    hospitalService.updateHospStatus(id,status);
    return R.ok().data("1",1);
    }

    /**
     * @description: 医院的详情信息
     * @author 化一帆
     * @date 2022/11/30 8:49
     */

    @ApiOperation(value = "医院详情信息")
    @GetMapping("showHospDetail/{id}")
    public R showHospDetail(@PathVariable String id){
       Map<String,Object> map=hospitalService.getHospById(id);
       return R.ok().data("hospital",map);
       //book bookingrule
    }
}
